{extend name="app/admin/view/base.html"/}
{block name="resources"}
<style>
    .layui-card-body{
        display: flex;
        justify-content: space-around;
    }
    .layui-card-body .money{
        font-size: 20px;
        color: #000;
        font-weight: bold;
        margin-top: 10px;
        text-align: center;
        max-width: 250px;
    }
    .layui-card-body .subhead{
        font-size: 12px;
        margin-left: 3px;
        cursor: pointer;
    }
    .layui-table-box {
        overflow: inherit;
    }
    .layui-table-header {
        overflow: inherit;
    }
    .layui-table-header .layui-table-cell{overflow: inherit;}
    .ns-prompt .iconfont{font-size: 16px;color: rgba(0,0,0,0.7);cursor: pointer;font-weight: 500;margin-left: 3px;}
    .ns-prompt-con{font-weight: 500;text-align: left}
    .img_block_sty{width:40px;height:40px;}
    .img_sty{width:100%;height:100%;}
</style>

{/block}
{block name='main'}
<!-- 筛选面板 -->
<div class="layui-collapse ns-tips">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">操作提示</h2>
        <ul class="layui-colla-content layui-show">
            <li>酒店列表，可在此展示所有酒店</li>
            <li>可添加酒店以及对酒店进行编辑和删除操作</li>
            <li>酒店管理中心：<a href="{:url('hotel/hotel/index/index')}" target="_blank" class="ns-text-color">{:url('hotel/hotel/index/index')}</a></li>
        </ul>
    </div>
</div>
<div class="ns-single-filter-box">
    <button class="layui-btn ns-bg-color" onclick="clickAdd()">添加酒店</button>
</div>
<div class="ns-screen layui-collapse" lay-filter="selection_panel">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">筛选</h2>
        <form class="layui-colla-content layui-form layui-show">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">酒店名称：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="hotel_name" placeholder="请输入酒店名称" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">酒店状态：</label>
                    <div class="layui-input-inline">
                        <select name="status">
                            <option value="">全部</option>
                            <option value="1">正常</option>
                            <option value="-1">关闭</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">推荐状态：</label>
                    <div class="layui-input-inline">
                        <select name="is_recommend">
                            <option value="">全部</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">添加时间：</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="start_time" readonly id="start_time" autocomplete="off" placeholder="开始时间" >
                        <i class="ns-calendar"></i>
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="end_time" readonly id="end_time" autocomplete="off" placeholder="结束时间" >
                        <i class="ns-calendar"></i>
                    </div>
                </div>
            </div>

            <div class="ns-form-row">
                <button class="layui-btn ns-bg-color" lay-submit lay-filter="search">筛选</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>
    </div>
</div>



<table id="account_list" lay-filter="account_list"></table>
{/block}
{block name="script"}
<script type="text/html" id="action">
    <div class="ns-table-btn">

        {{#  if(d.huifu_audit_status == 0){  }}
        <a class="layui-btn" lay-event="submit_huifu">提交汇付</a>
        {{#  }  }}

        <a class="layui-btn" lay-event="edit">编辑</a>
<!--        <a class="layui-btn" lay-event="detail">详情</a>-->
<!--        <a class="layui-btn" lay-event="apply_pay">转账</a>-->


        {{#  if(d.status == 1){  }}
        <a class="layui-btn" lay-event="frozen">关闭</a>
        {{#  }  }}
        {{#  if(d.status == -1){  }}
        <a class="layui-btn" lay-event="unfrozen">开启</a>
        {{#  }  }}


        <a class="layui-btn" lay-event="delete">删除</a>

    </div>
</script>

<script type="text/html" id="website_info">
    <div class="ns-table-tuwen-box">
        <div class="ns-img-box img_block_sty">
            {{#  if(d.hotel_img){  }}
            <img layer-src src="{{ns.img(d.hotel_img.split(',')[0])}}" class="img_sty"/>
            {{#  }else{  }}
            <img layer-src src="{:img($default_img.default_city_img)}" class="img_sty"/>
            {{#  }  }}
        </div>
        <div class="ns-font-box">
            <a href="javascript:;" class="ns-multi-line-hiding ns-text-color" title="{{d.hotel_name}}">{{d.hotel_name}}</a>
        </div>
    </div>
</script>

<script>
    function clickAdd()
    {
        location.href = ns.url('hotel://admin/hotel/add');
    }

    var start_time,end_time;
    layui.use(['laydate','form', 'laytpl'], function () {
        var laydate = layui.laydate,
            laytpl = layui.laytpl,
            form = layui.form,
            repeat_flag = false;

        form.render();

        //开始时间
        laydate.render({
            elem: '#start_time', //指定元素
            type: 'datetime'
            /* done: function(value, date, endDate){
                start_time = ns.date_to_time(value);
            } */
        });
        //结束时间
        laydate.render({
            elem: '#end_time', //指定元素
            type: 'datetime'
            /* done: function(value, date, endDate){
                end_time = ns.date_to_time(value);
            } */
        });

        /**
         * 搜索功能
         */
        form.on('submit(search)', function (data) {
            // data.field.start_time = start_time;
            // data.field.end_time = end_time;
            table.reload({
                page: {
                    curr: 1
                },
                where: data.field
            });
            return false;
        });

        var table = new Table({
            elem: '#account_list',
            url: ns.url("hotel://admin/hotel/lists"),
            cols: [
                [{
                    field: 'title',
                    title: '酒店信息',
                    unresize: 'false',
                    width: '15%',
                    templet: '#website_info',
                }, {
                    field: 'username',
                    title: '账号',
                    unresize: 'false',
                    width: '7%'
                },{

                    title: '地址',
                    unresize: 'false',
                    width: '15%',
                    templet: function (d) {
                        return d.full_address + d.address;
                    }
                },  {
                    field: 'telphone',
                    title: '酒店电话',
                    unresize: 'false',
                    width: '8%'
                },  {

                    title: '是否自营',
                    unresize: 'false',
                    width: '5%',
                    templet: function (d) {
                        return d.direct==1?'自营':'非自营';
                    }
                }, {

                    title: '推荐首页',
                    unresize: 'false',
                    width: '5%',
                    templet: function (d) {
                        return d.is_recommend==1?'是':'否';
                    }
                },{
                    field: 'sort',
                    title: '排序',
                    unresize: 'false',
                    width: '5%'
                }, {
                    title: '状态',
                    unresize: 'false',
                    width: '5%',
                    templet: function (data) {
                        return data.status == 1 ? '正常' : '关闭';
                    }
                },   {
                    field: 'commission_rate',
                    title: '抽成比例(%)',
                    unresize: 'false',
                    width: '6%'
                }, {
                    title: '录入人',
                    unresize: 'false',
                    width: '7%',
                    templet: function(data) {
                        return data.admin_username+'/'+data.admin_id;
                    }
                },{
                    title: '发布时间',
                    unresize: 'false',
                    width: '12%',
                    templet: function (res) {
                        if (res.create_time == 0) {
                            return '--';
                        } else {
                            return ns.time_to_date(res.create_time)
                        }
                    }
                }, {
                    title: '操作',
                    toolbar: '#action',
                    unresize: 'false',
                    width: '15%'
                }]
            ]
        });

        /**
         * 监听工具栏操作
         */
        table.tool(function (obj) {
            var data = obj.data;
            switch (obj.event) {
                /*case 'detail': //详情
                    location.href = ns.url("city://admin/website/detail", {"website_id": data.site_id});
                    break;*/
                case 'edit': //编辑
                    location.href = ns.url("hotel://admin/hotel/edit", {"hotel_id": data.hotel_id});
                    break;
                case 'apply_pay': //转账
                    applyPay(data);
                    break;
                case 'delete'://删除

                    layer.confirm('确定要删除该酒店吗?', function () {
                        if (repeat_flag) return;
                        repeat_flag = true;

                        $.ajax({
                            url: ns.url("hotel://admin/hotel/delete"),
                            data: {hotel_id: data.hotel_id},
                            dataType: 'JSON',
                            type: 'POST',
                            success: function (res) {
                                layer.msg(res.message);
                                repeat_flag = false;

                                if (res.code == 0) {
                                    table.reload();
                                }
                            }
                        });
                    });
                    break;
                case 'submit_huifu':

                    layer.confirm('确定要提交汇付审核吗?', function () {
                        if (repeat_flag) return;
                        repeat_flag = true;

                        $.ajax({
                            url: ns.url("hotel://admin/hotel/submitHuifu"),
                            data: {hotel_id: data.hotel_id},
                            dataType: 'JSON',
                            type: 'POST',
                            success: function (res) {
                                layer.msg(res.message);
                                repeat_flag = false;

                                if (res.code == 0) {
                                    table.reload();
                                }
                            }
                        });
                    });

                    break;
                case 'frozen'://冻结

                    layer.confirm('确定要关闭该酒店吗?', function () {
                        if (repeat_flag) return;
                        repeat_flag = true;

                        $.ajax({
                            url: ns.url("hotel://admin/hotel/frozen"),
                            data: {hotel_id: data.hotel_id,is_frozen:-1},
                            dataType: 'JSON',
                            type: 'POST',
                            success: function (res) {
                                layer.msg(res.message);
                                repeat_flag = false;

                                if (res.code == 0) {
                                    table.reload();
                                }
                            }
                        });
                    });

                    break;
                case 'unfrozen'://解冻

                    layer.confirm('确定要开启该酒店吗?', function () {
                        if (repeat_flag) return;
                        repeat_flag = true;

                        $.ajax({
                            url: ns.url("hotel://admin/hotel/frozen"),
                            data: {hotel_id: data.hotel_id,is_frozen:1},
                            dataType: 'JSON',
                            type: 'POST',
                            success: function (res) {
                                layer.msg(res.message);
                                repeat_flag = false;

                                if (res.code == 0) {
                                    table.reload();
                                }
                            }
                        });
                    });

                    break;
            }

            /**
             * 转账
             */
            function applyPay(data) {
                laytpl($("#applyPay").html()).render(data, function (html) {
                    layer_pass = layer.open({
                        title: '分站转账',
                        skin: 'layer-tips-class',
                        type: 1,
                        area: ['800px'],
                        content: html,
                    });
                });

                //转账凭证
                var paying_money_certificate_upload = new Upload({
                    elem: '#paying_money_certificate',
                    url: ns.url("admin/upload/upload")
                });

                //提交
                form.on('submit(repass)', function (data) {
                    field = data.field;

                    if (parseFloat(field.account) < parseFloat(field.money)) {
                        layer.msg('转账金额不能大于分站城市可用余额', {icon: 5, anim: 6});
                        return;
                    }

                    if (repeat_flag) return;
                    repeat_flag = true;

                    //删除图片
                    if(!data.field.paying_money_certificate) paying_money_certificate_upload.delete();

                    $.ajax({
                        url: ns.url("city://admin/withdraw/withdraw"),
                        data: data.field,
                        dataType: 'JSON',
                        type: 'POST',
                        success: function (res) {
                            layer.msg(res.message);
                            repeat_flag = false;

                            if (res.code == 0) {
                                layer.closeAll("page");
                                table.reload();
                            }
                        }
                    });

                });

                //表单验证
                form.verify({
                    money: function (value, item) {
                        var str = $(item).parents(".layui-form-item").find("label").text().split("*").join("");
                        str = str.substring(0, str.length - 1);

                        if (value <= 0) {
                            return str + "必须大于0";
                        }

                        var arrMen = value.split(".");
                        var val = 0;
                        if (arrMen.length == 2) {
                            val = arrMen[1];
                        }
                        if (val.length > 2) {
                            return str + "最多可保留两位小数";
                        }
                    }
                });
            }
        });

        $(".withdrawal-record").click(function () {
            location.href = ns.url("shop/shopwithdraw/lists");
        });


    })
</script>

<!-- 重置密码弹框html -->
<script type="text/html" id="applyPay">
    <div class="layui-form" lay-filter="form">

        <div class="layui-form-item">
            <label class="layui-form-label">分站城市：</label>
            <div class="layui-input-block">
                <p class="ns-input-text ">{{ d.site_area_name }}</p>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">可用余额：</label>
            <div class="layui-input-block">
                <p class="ns-input-text ">￥ {{d.account}}</p>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="required">*</span>转账金额：</label>
            <div class="layui-input-block ns-len-long">
                <input type="number" min="0" name="money" lay-verify="required|money" class="layui-input ns-len-short">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label img-upload-lable">支付凭证：</label>
            <div class="layui-input-block img-upload">
                <div class="upload-img-block">

                    <div class="upload-img-box">
                        <div class="ns-upload-default" id="paying_money_certificate">
                            <div class="upload">
                                <img src="ADMIN_IMG/upload_img.png"/>
                                <p>点击上传</p>
                            </div>
                        </div>
                        <div class="operation">
                            <div>
                                <i title="图片预览" class="iconfont iconreview js-preview" style="margin-right: 20px;"></i>
                                <i title="删除图片" class="layui-icon layui-icon-delete js-delete"></i>
                            </div>
                            <div class="replace_img js-replace">点击替换</div>
                        </div>
                        <input type="hidden" name="paying_money_certificate" value="">
                    </div>

                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">付款凭证说明：</label>
            <div class="layui-input-block ns-len-long">
                <textarea name="paying_money_certificate_explain" class="layui-textarea"></textarea>
            </div>
        </div>

        <input type="hidden" name="account" value="{{ d.account }}">
        <input type="hidden" name="website_id" value="{{ d.site_id }}">
        <div class="ns-form-row">
            <button class="layui-btn ns-bg-color" lay-submit lay-filter="repass">确定</button>
            <button class="layui-btn layui-btn-primary" onclick="closePass()">返回</button>
        </div>
    </div>
</script>
<script>
    function closePass() {
        layer.close(layer_pass);
    }
</script>
{/block}